package A1_二叉树;

public class LC_538把二叉搜索树转换为累加树 {
    public static class TreeNode{
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode(){}
        TreeNode(int val){
            this.val=val;
        }
        TreeNode(int val,TreeNode left,TreeNode right){
            this.val=val;
            this.left=left;
            this.right=right;
        }
    }
    int pre=0;
    public TreeNode convertBST(TreeNode root) {
        traversal(root);
        return root;
    }
    public void traversal(TreeNode cur){
        if(cur==null)
            return;
        traversal(cur.right);//右
        cur.val+=pre;
        pre=cur.val;
        traversal(cur.left);
    }
}
